/**
 * 项目名：phms3
 * 日期：    2019-12-08 11:33:38
 * Copyright (c) 2015- HTSC-版权所有
 */

package com.joysuch.wwyt.bp.repository;

import java.util.List;

import com.joysuch.wwyt.bp.entity.BpCertificate;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.querydsl.QuerydslPredicateExecutor;

/**
 * BpCertificateDao
 *
 */
public interface BpCertificateDao extends JpaRepository<BpCertificate, Long>, QuerydslPredicateExecutor<BpCertificate> {

    public Page<BpCertificate> findAll(Specification<BpCertificate> spec, Pageable pageable);

    public BpCertificate save(BpCertificate bean);

    public void delete(BpCertificate bean);

    public List<BpCertificate> findByUsetIdAndGroupId(Long userId, Long id);

    @Query("select t.name from BpCertificate c,BaseTypeGroupItem t where c.groupId=t.id and c.usetId=?1 and t.code=?2")
    List<String> findCertNameByUserIdAndType(Long userId, String type);

    @Query("select c from BpCertificate c,BaseTypeGroupItem t where c.groupId=t.id and c.usetId=?1 and t.code=?2")
    List<BpCertificate> findCertByUserIdAndType(Long userId, String type);

    @Query("select c.usetId, t.name from BpCertificate c,BaseTypeGroupItem t where c.groupId=t.id and c.usetId in (?1) and t.code=?2")
    List<BpCertificate> findCertNameByUserIdsAndType(List<Long> userId, String type);
}
